package com.server.modules.api.service;

import com.server.common.persistence.Page;
import com.server.modules.api.dao.LoanTypeAPIDao;
import com.server.modules.api.vo.BaseQueryVo;
import com.server.modules.api.vo.list.LoanTypeList;
import com.server.modules.api.vo.LoanTypeListVo;
import com.server.modules.sys.entity.loan.LoanType;
import com.server.modules.sys.service.loan.LoanTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2016/7/22.
 */
@Service
public class LoanTypeListAPIService extends LoanTypeService {
	@Resource
	private LoanTypeAPIDao loanTypeAPIDao;

	public LoanTypeList selectLoanTypeList(BaseQueryVo vo) {
		LoanType type = new LoanType();
		Page<LoanType> page = new Page<LoanType>();

		String orderBy = "orderids asc";
		if (vo != null && vo.getPage() != null) {
			orderBy += " limit " + (vo.getPage().getPageNo() - 1) + ", " + vo.getPage().getPageSize();
		}
		page.setOrderBy(orderBy);
		type.setPage(page);
		List<LoanType> list = dao.findAllList(type);

		if (list == null || list.size() == 0) {
			return null;
		}
		return new LoanTypeList(list);
	}

	public int selectLoanTypeCount() {
		return loanTypeAPIDao.selectTypeCount();
	}
}
